import {
    fetchListExpressTemplate,
    fakeDeleteExpressTemplate,
    fakeSaveExpressTemplate,
    fetchListExpress,
    fakeSendExpress,
    fetchListExpressCompany
} from '@/services/ExpressTemplateServices';
import { notification } from 'antd';
const expressTemplate = {
    namespace: 'expressTemplate',
    state: {
        list: { list: [], total: 0 },
        organizationExpressList: { list: [], total: 0 },
    },
    effects: {

        *fetchListExpressCompany({ payload, callback }, { call, put }) {
            const response = yield call(fetchListExpressCompany, payload);
            if (!response) return;
            const {
                content: { expressCompanyList, },
            } = response;
            callback && callback(expressCompanyList)
        },
        *fetchListExpress({ payload, callback }, { call, put }) {
            const response = yield call(fetchListExpress, payload);
            if (!response) return;
            const {
                content: { organizationExpressList, total },
            } = response;
            yield put({
                type: 'save',
                payload: {
                    organizationExpressList: {
                        list: organizationExpressList,
                        total: total,
                    },
                },
            });
        },

        *fakeSendExpress({ payload, callback }, { call, put }) {
            const response = yield call(fakeSendExpress, payload);
            if (!response) return;
            notification.success({
                message: '温馨提示',
                description: '发货成功',
            });
            callback && callback();
        },



        *fetchListExpressTemplate({ payload, callback }, { call, put }) {
            const response = yield call(fetchListExpressTemplate, payload);
            if (!response) return;
            const {
                content: { expressTemplateList, total },
            } = response;
            yield put({
                type: 'save',
                payload: {
                    list: {
                        list: expressTemplateList,
                        total: total,
                    },
                },
            });
        },
        *fakeSaveExpressTemplate({ payload, callback }, { call, put }) {
            const response = yield call(fakeSaveExpressTemplate, payload);
            if (!response) return;
            notification.success({
                message: '温馨提示',
                description: '保存成功',
            });
            callback && callback();
        },

        *fakeDeleteExpressTemplate({ payload, callback }, { call, put }) {
            const response = yield call(fakeDeleteExpressTemplate, payload);
            if (!response) return;
            notification.success({
                message: '温馨提示',
                description: '删除成功',
            });
            callback && callback();
        },

    },

    reducers: {
        save(state, { payload }) {
            return {
                ...state,
                ...payload,
            };
        },
    },
};
export default expressTemplate;
